package com.mane.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mane.entity.DTO.BaseDTO;
import com.mane.entity.PageData;
import com.mane.entity.DTO.TrainerSearchDTO;
import com.mane.mapper.TrainerMapper;
import com.mane.entity.VO.TrainerListVO;
import com.mane.pojo.Trainer;
import com.mane.service.ITrainerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrainerServiceImpl extends ServiceImpl<TrainerMapper, Trainer> implements ITrainerService {
    @Autowired
    private TrainerMapper trainerMapper;

    @Override
    public PageData<Trainer> list2(BaseDTO baseDTO) {
        //创建分页对象
        Page<Trainer> page = new Page<>(baseDTO.getCurrentPage(), baseDTO.getPageSize());
        //分页查询
        Page<Trainer> trainerPage = trainerMapper.selectPage(page, null);
        //创建pagedate对象
        PageData<Trainer> pageData = new PageData<>();
        pageData.setTotal(trainerPage.getTotal());
        pageData.setData(trainerPage.getRecords());
        //返回数据
        return pageData;
    }

    @Override
    public PageData<TrainerListVO> listSearch(TrainerSearchDTO trainerSearchDTO) {
        //创建分页对象
        Page<TrainerListVO> page = new Page<>(trainerSearchDTO.getCurrentPage(), trainerSearchDTO.getPageSize());
        //分页查询
        page = trainerMapper.listSearch(page, trainerSearchDTO);        //构建PageData对象
        PageData<TrainerListVO> pageData = new PageData<>();
        pageData.setTotal(page.getTotal());
        pageData.setData(page.getRecords());
        //返回数据
        return pageData;
    }

}
